﻿using System;
using System.Data;
using CoreLab.Oracle; //using Devart.Data.Oracle; //using Oracle.DataAccess.Client;
using System.Web;
using System.Web.Caching;
using System.Collections.Generic;

using LMD.Constant;
using LMD.Lib.DataClass;
using LMD.Lib.Oracle;

namespace Cached
{
    /// <summary>
    /// Summary description for MonitoringMRTGTable
    /// </summary>
    public class MonitoringMRTGTable : CacheAbstraction
    {
        public DataTable GetMRTGList()
        {
            return GetMRTGList(false);
        }
        public DataTable GetMRTGList(bool bForceRefresh)
        {
            String sxCacheKey = KCache.T_MONITORING_MRTG;

            if (bForceRefresh)
            {
                HttpRuntime.Cache.Remove(sxCacheKey);
            }
            if (HttpRuntime.Cache[sxCacheKey] == null)
            {
                DBLib dbl = new DBLib();

                String sxQuery =
                @"
                select
                    t1.T_MONITORING_MRTG_ID,
                    v2.CUSTOMER_ID,
                    v2.COMPANY_NAME,
                    t1.NETWORK_NO,
                    t1.NOTE,
                    t1.START_DATE,
                    t1.END_DATE,
                    v3.ICP_USER_ID,
                    v3.EMPLOYEE_NAME,
                    t1.T_FILE_UPLOAD_ID,
                    t2.ORIGINAL_FILENAME
                from 
                    T_MONITORING_MRTG t1
                left join 
                    V_ICP_CUSTOMER_NETWORK v1
                on
                    t1.NETWORK_NO = v1.NETWORK_NO
                left join
                    V_ICP_COMPANY_CAR_SALES v2
                on
                    v1.CUSTOMER_ID = v2.CUSTOMER_ID
                left join
                    V_ICP_USER v3
                on
                    t1.CREATE_BY = v3.ICP_USER_ID
                left join
                    T_FILE_UPLOAD t2
                on
                    t1.T_FILE_UPLOAD_ID = t2.T_FILE_UPLOAD_ID
                ";
                DataTable dt = dbl.GetDataTable(sxQuery);

                AddToCache(sxCacheKey, dt, CacheType.FiveMinutes);
                
            }
            return (DataTable)HttpRuntime.Cache[sxCacheKey];
        }
        
        
        public override String GetCacheFilename()
        {
            return KCache.Filename.MRTG;
        }
    }
}